import 'package:flutter/material.dart';

class CustomDialog extends StatelessWidget {
  final String title;
  final String content;
  final String confirmText;
  final String cancelText;
  final VoidCallback? onCancel;
  final VoidCallback? onConfirm;
  final bool bIsShowCancelBtn;
  final bool bIsShowOkBtn;

  const CustomDialog({
    Key? key,
    this.title = "",
    this.content = "",
    this.confirmText = 'OK',
    this.cancelText = 'Cancel',
    this.bIsShowCancelBtn = true,
    this.bIsShowOkBtn = true,
    this.onConfirm,
    this.onCancel,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        if (!bIsShowCancelBtn && !bIsShowOkBtn)
          AppBar(
            automaticallyImplyLeading: false,
            backgroundColor: Colors.transparent,
            actions: [
              IconButton(
                icon: const Icon(
                  Icons.close,
                  size: 30,
                  color: Colors.white,
                ),
                onPressed: () {
                  Navigator.of(context).pop(false);
                },
              )
            ],
          ),
        AlertDialog(
          title: title.isNotEmpty
              ? Text(title,
                  style: const TextStyle(
                      fontSize: 18, fontWeight: FontWeight.bold))
              : null,
          content: content.isNotEmpty
              ? Text(
                  content,
                  style: const TextStyle(fontSize: 18),
                )
              : null,
          actions: <Widget>[
            if (bIsShowCancelBtn)
              TextButton(
                onPressed: () {
                  if (onCancel != null) {
                    onCancel!();
                  }
                  Navigator.of(context).pop(false);
                },
                child: Text(cancelText),
              ),
            if (bIsShowOkBtn)
              TextButton(
                onPressed: () {
                  if (onConfirm != null) {
                    onConfirm!();
                  }
                  Navigator.of(context).pop(true);
                },
                child: Text(confirmText),
              ),
          ],
        )
      ],
    );
  }
}


/*
使用:
        showDialog(
                    context: context,
                    builder: (context) => CustomDialog(
                      title: 'Confirmation',
                      content: 'Are you sure you want to proceed?',
                      onConfirm: () {
                        // 这里处理确认按钮的逻辑
                        print('Confirmed');
                      },
                    ),
                  );

*/